import time

import page
from base.base import Base


class PageCart(Base):
    # 点击购物车链接
    def page_cart_link(self):
        self.base_refresh()
        self.base_click_element(page.product_cart_link)

    # 点击增加按钮
    def page_add_number_btn(self):
        self.base_click_element(page.get_cart_elements(user_id=1)['add_btn'])

    # 点击减少按钮
    def page_reduce_number_btn(self):
        self.base_click_element(page.get_cart_elements(user_id=1)['reduce_btn'])

    # 点击第一个商品的选中框
    def page_click_first_product_select_box(self):
        self.base_click_element(page.get_cart_elements(user_id=1)['select_box'])

    # 点击结算按钮
    def page_click_pay_btn(self):
        self.base_click_element(page.product_pay_btn)

    # 选择收货地址
    def page_choose_receive_address(self):
        self.base_click_element(page.product_receive_address)

    # 选择支付方式
    def page_choose_pay_type(self):
        self.base_click_element(page.product_pay_type)

    # 点击提交订单
    def page_click_submit_order(self):
        self.base_click_element(page.product_submit_order)

    # 点击我的订单
    def page_click_my_order(self):
        self.base_click_element(page.product_my_order)

    # 点击刷新按钮
    def page_click_refresh_btn(self):
        self.base_refresh()

    # 点击收货按钮
    def page_click_receive_btn(self):
        self.base_click_element(page.get_cart_elements(user_id=1)['receive_btn'])

    # 点击提示框确认按钮
    def page_click_confirm_btn(self):
        self.base_click_element(page.product_confirm_btn)

    def page_scroll_to_submit_order(self):
        self.base_scroll_to_element(page.product_submit_order)

    def page_cart(self):
        self.page_add_number_btn()
        time.sleep(1)
        self.page_reduce_number_btn()
        time.sleep(1)
        self.page_click_first_product_select_box()
        time.sleep(1)
        self.page_click_pay_btn()
        time.sleep(1)

    def page_order(self):
        self.page_choose_receive_address()
        self.page_scroll_to_submit_order()
        self.page_choose_pay_type()
        self.page_click_submit_order()
        self.page_click_my_order()

    def page_receipt(self):
        self.page_click_receive_btn()
        self.page_click_confirm_btn()
